import { registerClass } from "../../../cfw/tools/class_decorator";
import { SDKSystem } from "../../core/system/SDKSystem";
import { ResultCallback, ResultState } from "../../SDKDefine";


@registerClass('VivoSystem')
export class VivoSystem extends SDKSystem {
    showToast(title: string) {
        this.sdk.showToast({
            message: title
        })
    }


    vibrateShort() {
        this.sdk.vibrateShort({
            success: function (res: any) { },
            fail: function (res: any) { },
            complete: function (res: any) { }
        })
    }

    canInstallShortcut(func: ResultCallback) {
        this.sdk.hasShortcutInstalled({
            success: function (res: any) {
                // 判断图标未存在时，创建图标
                console.log('canInstallShortcut res ', res)
                if (res == false) {
                    func(ResultState.YES)
                } else {
                    func(ResultState.NO)
                }
            },
            fail: function (err: any) {
                console.log('canInstallShortcut err ', err)
                func(ResultState.NO)
            },
            complete: function () {
                console.log('canInstallShortcut complete ')
                // func(false)
            }
        })
    }

    previewImage(_tempFilePath: string) {
        this.sdk.previewImage({
            uris: [_tempFilePath],
            success: (res: any) => {
                console.log('Preview image success.');
                // self.label = '';
            }
        });
    }


    installShortcut(result: ResultCallback) {
        this.sdk.installShortcut({
            success: function () {
                // 执行用户创建图标奖励
                console.log(' 安装成功 ')
                result(ResultState.YES)
            },
            fail: function (err: any) {
                console.log(' 安装失败 ', err)
                result(ResultState.NO)
            },
            complete: function () {
                // result(false)
            }
        })

    }



    navigateToMiniProgram(appID: string) {
        this.sdk.navigateToMiniGame({
            pkgName: appID,
            success: function () { },
            fail: function (res: any) {
                // console.log(JSON.stringify(res))
            }
        })
    }

    exitApplication() {
        this.sdk.exitApplication();
    }

    hasShare() {
        // const version = this.sdk.getSystemInfoSync().platformVersionCode
        // return version >= 1056;
        return false
    }
}